package telas.login;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.KeyStroke;

import com.jgoodies.forms.factories.DefaultComponentFactory;

import controle.login.ControleLogin;
import controle.login.ControleLoginSwing;

import java.awt.Font;
import java.awt.Color;
import javax.swing.JPasswordField;
import javax.swing.UIManager;
import java.awt.SystemColor;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.ImageIcon;


public class Login extends JFrame {

	private JPanel contentPane;
	private JTextField tfUsuario;
	private JLabel lblSenha;
	private JLabel lblAcessoAoSistema;
	private JPasswordField tfSenha;
	private JLabel lblFundo;
	private JLabel lblRetangulo;
	private JLabel logo;
	private JButton btnEntrar;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Login frame = new Login();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Login() {
		setResizable(false);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(800, 600);
		setVisible(true);
		setLocationRelativeTo(null);
		contentPane = new JPanel();
		contentPane.setBackground(SystemColor.controlHighlight);
		contentPane.setForeground(Color.DARK_GRAY);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		InputMap imap = contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 

		imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), "panel.login");


		// associate the names with actions

		ActionMap amap = contentPane.getActionMap();
		amap.put("panel.login", new ControleLoginSwing(this, new ControleLogin(), "login"));
		
		
		JLabel lblUsuario = new JLabel("Usu\u00E1rio");
		lblUsuario.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblUsuario.setForeground(SystemColor.controlLtHighlight);
		lblUsuario.setBounds(146, 182, 53, 16);
		
		lblSenha = new JLabel("Senha");
		lblSenha.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblSenha.setForeground(SystemColor.controlLtHighlight);
		lblSenha.setBounds(146, 232, 42, 16);
		
		btnEntrar = new JButton("Entrar");
		btnEntrar.setBounds(146, 293, 159, 25);
		btnEntrar.setFont(new Font("Tahoma", Font.BOLD, 12));
		btnEntrar.setForeground(Color.DARK_GRAY);
		btnEntrar.addActionListener(new ControleLoginSwing(this, new ControleLogin()));
		lblAcessoAoSistema = DefaultComponentFactory.getInstance().createTitle("Acesso ao Sistema");
		lblAcessoAoSistema.setBounds(274, 125, 249, 32);
		lblAcessoAoSistema.setForeground(SystemColor.controlLtHighlight);
		lblAcessoAoSistema.setFont(new Font("Tahoma", Font.BOLD, 26));
		
		tfUsuario = new JTextField();
		tfUsuario.setBounds(146, 200, 159, 20);
		tfUsuario.setColumns(10);
		tfUsuario.addKeyListener(new KeyListener() {
			public void keyPressed(KeyEvent e) {
				if(e.getKeyCode() == KeyEvent.VK_ENTER) {
					tfSenha.requestFocus(); 
				}
			}
			public void keyReleased(KeyEvent e) { }
			public void keyTyped(KeyEvent e) { }
		});
		
		tfSenha = new JPasswordField();
		tfSenha.setBounds(146, 249, 159, 20);
		contentPane.setLayout(null);
		contentPane.add(lblAcessoAoSistema);
		contentPane.add(lblUsuario);
		
		logo = new JLabel("");
		logo.setIcon(new ImageIcon(Login.class.getResource("/telas/sistema/figuras/LogoGrande.png")));
		logo.setBounds(416, 182, 260, 140);
		contentPane.add(logo);
		contentPane.add(tfUsuario);
		contentPane.add(lblSenha);
		contentPane.add(tfSenha);
		contentPane.add(btnEntrar);
		
		lblRetangulo = new JLabel("");
		lblRetangulo.setIcon(new ImageIcon(Login.class.getResource("/telas/sistema/figuras/retanguloTransparente2.png")));
		lblRetangulo.setBounds(82, 105, 631, 258);
		contentPane.add(lblRetangulo);
		
		lblFundo = new JLabel("");
		lblFundo.setIcon(new ImageIcon(Login.class.getResource("/telas/sistema/figuras/fundo.jpg")));
		lblFundo.setBounds(0, 0, 794, 572);
		contentPane.add(lblFundo);
	}
	
	public JTextField getTfUsername() {
		return tfUsuario;
	}

	public JPasswordField getTfPasswordField() {
		return tfSenha;
	}

	public JButton getBtnEntrar() {
		return btnEntrar;
	}
}
